package com.wisezone.studentmanger.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wisezone.studentmanger.dao.StudentDao;
import com.wisezone.studentmanger.dao.StudentDaoImpl;
import com.wisezone.studentmanger.model.Student;

/**
 * 
 * servlet作用: 1.接收客户端请求 2.调用业务代码获取结果 3.响应用数据
 * 
 *
 * @author zhousir
 * @创建时间 2017年10月11日
 */
public class StudentServlet extends HttpServlet {
	private StudentDao studentDao;

	@Override
	public void init(ServletConfig config) throws ServletException {
		studentDao = new StudentDaoImpl();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		
		List<Student> studentLists = studentDao.showStudentAll();
		PrintWriter pw = response.getWriter();
		
		pw.println("<html>"
						+ "<head>"
							+ "<meta charset=\"utf-8\"/>"
							+ "<title>员工表</title>"
							+ "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.java1704.com/StudentManger/css/department.css\">"
						+ "</head>"
						+ "<body>"
							+ "<div class=\"emp_contaner\">  "
									+ "<h3>员工信息表</h3>"
									+ "<table>"
										+ "<tr>"
											+ "<th>员工编号</th>"
											+ "<th>员工名称</th>"
											+ "<th>入职时间</th>"
											+ "<th colspan=\"2\">操作</th>"
										+ "</tr>");
		
										for(Student student : studentLists){
											pw.println("<tr>"
													+ "<td>"+student.getNumber()+"</td>"
													+ "<td>"+student.getName()+"</td>"
													+ "<td>"+student.getDateTime()+"</td>"
													+ "<td><a href=\"#\">修改</a></td>"
													+ "<td><a href=\"#\">删除</a></td>"
													+"</tr>");
										}
			

		                   pw.println( "</table>"
							+ "</div>"
						+ "</body>"
				 + "</html>");
		
		pw.close();
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
